package com.llkj.contractmanagement.customview;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.llkj.contractmanagement.R;
import com.llkj.contractmanagement.utils.ScreenUtil;


public class SelectImageDialog extends Dialog implements View.OnClickListener {
    private View other_view;
    private Button dialog_cancel, choose_by_local, choose_by_camera;
    private ItemClickListener itemClickListener;
    private ItemForIconClickListener itemForIconClickListener;
    private Context context;

    public SelectImageDialog(Context context, int theme) {
        super(context, theme);
        this.context = context;
    }

    public void setItemClickListener(ItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

    public void setItemForIconClickListener(ItemForIconClickListener itemForIconClickListener) {
        this.itemForIconClickListener = itemForIconClickListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View view = getLayoutInflater().inflate(R.layout.dialog_choose_img, null);
        view.setMinimumWidth(ScreenUtil.getScreenWidth(context));
        setContentView(view);
        other_view = findViewById(R.id.other_view);
        dialog_cancel = (Button) findViewById(R.id.dialog_cancel);
        choose_by_local = (Button) findViewById(R.id.choose_by_local);
        choose_by_camera = (Button) findViewById(R.id.choose_by_camera);
        other_view.setOnClickListener(this);
        dialog_cancel.setOnClickListener(this);
        choose_by_local.setOnClickListener(this);
        choose_by_camera.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.other_view:
                if (itemClickListener != null) {
                    dismiss();
                }
                break;
            case R.id.dialog_cancel:
                dismiss();
                break;
            case R.id.choose_by_camera:
                if (itemClickListener != null) {
                    itemClickListener.takephoto();
                    dismiss();
                }
                if (itemForIconClickListener != null) {
                    itemForIconClickListener.takephotoForIcon();
                    dismiss();
                }
                break;
            case R.id.choose_by_local:
                if (itemClickListener != null) {
                    itemClickListener.album();
                    dismiss();
                }
                if (itemForIconClickListener != null) {
                    itemForIconClickListener.albumForIcon();
                    dismiss();
                }
                break;
        }
    }

    public interface ItemClickListener {
        void album();

        void takephoto();

    }
    public interface ItemForIconClickListener {
        void albumForIcon();

        void takephotoForIcon();

    }
}
